using System;
using System.Net;
using System.Web;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;

namespace ErrorSense.Client.ErrorApi
{
	/// <summary>
    /// ErrorHandlingModule class is responsible for handling application errors
	/// </summary>
    [Serializable()]
    public sealed class ErrorHandlingModule : IHttpModule
	{
        public ErrorHandlingModule()
		{
		}

		public void Dispose()
		{
		}

		public void Init(HttpApplication context)
		{
			context.Error += new EventHandler(this.OnEnter);
		}

		private void OnEnter(object source, EventArgs eventArg)
		{
			try
			{
                if (source != null)
                {
                    System.Web.HttpApplication app = (HttpApplication)source;

                    Exception ex = app.Server.GetLastError();
                    ErrorApiAdapter.SendNotification(ex, true);
                }
            }
			catch (Exception oError)
			{
                throw oError;
            }
		}
	}
}
					
